package org.jeecg.modules.waybill.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.waybill.doc.WlhyWaybillDoc;
import org.jeecg.modules.waybill.dto.WlhyWaybillDto;
import org.jeecg.modules.waybill.entity.WlhyWaybill;
import org.jeecg.modules.waybill.service.IWlhyWaybillService;
import org.jeecg.modules.waybill.vo.WlhyWaybillVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 订单表
 * @Author: jeecg-boot
 * @Date: 2024-04-11
 * @Version: V1.0
 */
@Api(tags = "订单表")
@RestController
@RequestMapping("/waybill-api/waybill/wlhyWaybill")
@Slf4j
public class WlhyWaybillApi extends JeecgController<WlhyWaybill, IWlhyWaybillService> {
    @Autowired
    private IWlhyWaybillService wlhyWaybillService;

    /**
     * 分页列表查询
     *
     * @param waybillDto
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "订单表-分页列表查询")
    @ApiOperation(value = "订单表-分页列表查询", notes = "订单表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<WlhyWaybillDoc>> queryPageList(@Validated  WlhyWaybillDto waybillDto,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        IPage<WlhyWaybillDoc> pageList = wlhyWaybillService.search(waybillDto,pageNo,pageSize);
        return Result.OK(pageList);
    }

    /**
     * 司机抢单
     *
     * @param waybillId
     * @return
     */
    @AutoLog(value = "订单表-司机抢单")
    @ApiOperation(value = "订单表-司机抢单", notes = "订单表-司机抢单")
    @RequestMapping(value = "/skillOrder", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> skillOrder(@RequestParam String waybillId) {
        wlhyWaybillService.skillOrder(waybillId);
        return Result.OK("抢单成功!");
    }

  /**
     * 装货
     *
     * @param waybillId
     * @return
     */
    @AutoLog(value = "订单表-装货")
    @ApiOperation(value = "订单表-装货", notes = "订单表-装货")
    @RequestMapping(value = "/loadCargo", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> loadCargo(@RequestParam String waybillId) {
        wlhyWaybillService.loadCargo(waybillId);
        return Result.OK("装货成功!");
    }


    /**
     * 发车
     *
     * @param waybillId
     * @return
     */
    @AutoLog(value = "订单表-发车")
    @ApiOperation(value = "订单表-发车", notes = "订单表-发车")
    @RequestMapping(value = "/startCar", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> startCar(@RequestParam String waybillId) {
        wlhyWaybillService.startCar(waybillId);
        return Result.OK("发车成功!");
    }

 /**
     * 签收
     *
     * @param waybillId
     * @return
     */
    @AutoLog(value = "订单表-签收")
    @ApiOperation(value = "订单表-签收", notes = "订单表-签收")
    @RequestMapping(value = "/signFor", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> signFor(@RequestParam String waybillId) {
        wlhyWaybillService.signFor(waybillId);
        return Result.OK("签收成功!");
    }




}
